Skip to content

Conversation

@NuroDev
Copy link
Contributor

@NuroDev NuroDev commented Jan 13, 2026

Fixes #10400, #9709 and #8475

Currently, if you run wrangler types it only generates TypeScript types for bindings (KVNamespace, D1Database, etc) defined in the top-level configuration (or a single environment when using --env). Now, by default, it collects & generates types for bindings from all environments in your configuration.

This ensures your generated types include all bindings that might be used across different deployment environments (e.g., staging, production), preventing TypeScript errors when accessing environment-specific bindings.

Additionally, If the same binding name exists with different types across environments (e.g., CACHE is a KV namespace in one environment but an R2 bucket in another), an error will be thrown to prevent type conflicts.


A picture of a cute animal (not mandatory, but encouraged)

@NuroDev NuroDev self-assigned this Jan 13, 2026
@changeset-bot
Copy link

changeset-bot bot commented Jan 13, 2026

🦋 Changeset detected

Latest commit: 9a5d3c6

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 13, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@11893

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@11893

miniflare

npm i https://pkg.pr.new/miniflare@11893

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@11893

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@11893

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@11893

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@11893

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@11893

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@11893

wrangler

npm i https://pkg.pr.new/wrangler@11893

commit: 9a5d3c6

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick first pass, added some comment.

I really like the added comments 🙏

@NuroDev NuroDev marked this pull request as ready for review January 15, 2026 14:30
@NuroDev NuroDev requested a review from a team as a code owner January 15, 2026 14:30
Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some comments as an initial first review, please have a look 🙂🙏

Comment on lines +1667 to +1670
MY_VAR?: \\"a var\\";
MY_VAR_A: \\"A (prod)\\" | \\"A (stag)\\" | \\"A (dev)\\";
MY_VAR_B?: {\\"value\\":\\"B (prod)\\"} | {\\"value\\":\\"B (dev)\\"};
MY_VAR_C?: [1,2,3] | [\\"a\\",\\"b\\",\\"c\\"];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure if this would constitute a breaking change or a bug fix? Since technically it's sort of both?
Previously Env set variables to be a required union, regardless whether the variable existed across all environments or not. This has now been changed such that variables in Env are still a union, but are now optional unless that variable exists across all named environments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mh.... the same can be said to any other binding no?

For example I could have something like:

	"kv_namespaces": [{
		"binding": "MY_KV",
		"id": "xxx"
	}],
	"env": {
		"my_env": {
			"kv_namespaces": []
		}
	}

with the previous iteration of wrangler you'd get MY_KV: KVNamespace while now you'd get MY_KV?: KVNamespace (since MY_KV is not declared for the my_env environment) no? (so here again users could go from a normal variable before to an optional one after)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes pretty much. Based on your config above my concern is that users would now have to modify their code to account for these new / fixed types.

For comparison sake, here is npx wrangler@latest types vs pnpm run cf-typegen on this branch with the config you shared above.

Before

before

After

after

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification, yeah it's pretty much as I thought...

I agree that there's the risk of breaking folks... I personally would think that this is ok since this makes the types more accurate (so it could be considered a bugfix?) but you can ask for a second opinion from the team someone might think of this differently (we could make this opt-in if we were really concerned 🤔)

Copy link
Member

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, sorry but I still need to give this another review (or 2) before feeling somewhere ok approving it.

I also need to run the functionality locally.

Also given the size of the PR I think it would be appropriate if there are at least a couple of approvals here before we merge this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

can't generate RPC types when the service binding is targeting a specific environment

4 participants